package khiem.gwt.demo.client;

import com.google.gwt.gadgets.client.DynamicHeightFeature;
import com.google.gwt.gadgets.client.Gadget;
import com.google.gwt.gadgets.client.Gadget.AllowHtmlQuirksMode;
import com.google.gwt.gadgets.client.Gadget.ModulePrefs;
import com.google.gwt.gadgets.client.Gadget.UseLongManifestName;
import com.google.gwt.gadgets.client.NeedsDynamicHeight;
import com.google.gwt.gadgets.client.UserPreferences;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
@UseLongManifestName(false)
@AllowHtmlQuirksMode(false)
@ModulePrefs(title="Total Inter", author="Do Hoang Khiem", description="A gadget to grab all news, info about FC Inter and Italia football" )
public class TotalInter extends Gadget<RSSPreferences> implements NeedsDynamicHeight {

  DynamicHeightFeature heighFeature;
  
  VerticalPanel mainPanel;
  
  @Override
  protected void init(RSSPreferences rssPref) {
    RootPanel rootPanel = RootPanel.get();
    mainPanel = new VerticalPanel();
    rootPanel.add(mainPanel);
    
    Label label = new Label();
    String[] list = rssPref.rssList().getValue();
    if (list == null || list.length == 0) label.setText("No data");
    StringBuilder value = new StringBuilder();
    for (int i = 0; i < list.length; i++) {
      value.append(list[i]);
      value.append(" ");
    }
    label.setText(value.toString());
    mainPanel.add(label);
    
    heighFeature.adjustHeight();
  }

  @Override
  public void initializeFeature(DynamicHeightFeature feature) {
    this.heighFeature = feature;
  }

}
